package com.yl.applicationsecurity.controller;

import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.*;
import com.yl.applicationsecurity.service.KunpengSqlInjectionService;
import com.yl.applicationsecurity.service.ScriptStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description:
 * @date 2025-03-25 17:10:16
 */
@RestController
@RequestMapping("/kunpengSqlInjection")
public class KunpengSqlInjectionController {

    @Autowired
    private KunpengSqlInjectionService kunpengSqlInjectionService;

    @Autowired
    private ScriptStateService scriptStateService;



    @PostMapping("/list")
    public Result list(Integer[] statusArray,String[] nationSelect, KunpengSqlInjection kunpengSqlInjection, @RequestParam(required = false) Date[] startAndEndDate, @RequestParam(defaultValue = "1", value = "pageNum")Integer pageNum
            , @RequestParam(defaultValue = "10", value = "pageSize")Integer pageSize){
        PageInfo<KunpengSqlInjection> kunpengSqlInjectionList = null;

        if(startAndEndDate!=null&&startAndEndDate.length!=2){
            kunpengSqlInjectionList = kunpengSqlInjectionService.findListByKunpengSqlInjection(statusArray,nationSelect,kunpengSqlInjection,null,null,pageNum,pageSize);
        }else{
            kunpengSqlInjectionList = kunpengSqlInjectionService.findListByKunpengSqlInjection(statusArray,nationSelect,kunpengSqlInjection,startAndEndDate[0],startAndEndDate[1],pageNum,pageSize);
        }
        return Result.success(kunpengSqlInjectionList);
    }


    @RequestMapping("/updateStatus")
    public Result updateStatus(HttpServletRequest request, String[]  ids, Integer updateStatus) {


        if(kunpengSqlInjectionService.updateStatus(  ids, updateStatus)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }



    @PostMapping("/insert")
    public Result insert(@RequestBody List<KunpengSqlInjection> list) {

        scriptStateService.updateDate("鲲鹏SQL注入监控");

        for (KunpengSqlInjection kunpengSqlInjection : list){
            kunpengSqlInjectionService.insert(kunpengSqlInjection);
        }
        return  Result.success("修改成功");

    }


}

